from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(60*2+1):       
            dot1=Dot([-500,5*(i-60),0]).set_opacity(0.5)
            dot2=Dot([500,5*(i-60),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(100*2+1):        
            dot3=Dot([(i-100)*5,-300,0]).set_opacity(0.5)
            dot4=Dot([(i-100)*5,300,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        self.play(self.camera.frame.animate.scale(1).move_to([0,0,0]))
        
        #题目出现
        text = Tex(r"\text{(张1000)若函数}$f\left( x\right) $\text{满足关系式}$f^{'}\left( x\right) +af\left( x\right) =\int _{x}^{0}f\left( t\right) dt,$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,23,0])
        text0 = Tex(r"$a >0,$\text{求}$\int _{0}^{+\infty }f\left( x\right) dx$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,19,0])
        text1 = Tex(r"\text{(2020年)设函数}$f\left( x\right) $\text{满足}$f''\left( x\right) +af'\left( x\right) +f\left( x\right) =0( a > 0) $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,10,0])
        text10 = Tex(r"\text{,且}$f\left( 0\right) =m,f'\left( 0\right) =n$\text{,则}$\int _{0}^{+\infty }f\left( x\right) dx=$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,4,0])
        text2 = Tex(r"\text{(2016年)设函数}$f\left( x\right) $\text{满足方程}$y''+2y'+ky=0( 0 <k < 1) $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-3,0])
        text20 = Tex(r"\text{(1)证明:反常积分}$\int _{0}^{+\infty }y\left( x\right) dx$\text{收敛}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,-7,0])
        text200 = Tex(r"\text{(2)若}$y\left( 0\right) =1,y'\left( 0\right) =1,$\text{求}$\int _{0}^{+\infty }y\left( x\right) dx$\text{的值}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-11,0])
        text5 = Tex(r"$\Rightarrow I=\int \left( \dfrac{1}{t}-\dfrac{1}{t+1}\right) dt$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-15,0])
        text6 = Tex(r"$\Rightarrow I=\ln \left| \dfrac{t}{1+t}\right| +c$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-23,0])
        text7 = Tex(r"$\Rightarrow I=\ln \left| \dfrac{xe^{x}}{1+xe^{x}}\right| +c$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-31,0])






        
        self.play(Create(text),Create(text0))
        self.wait(0.2)
        self.play(Create(text1),Create(text10),Create(text2),Create(text20),Create(text200))
        #镜头拉回
          #分析文本
        #text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-38,12.5,0])
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)
        #题目向上移动
       
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=13,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([-5,19,0])
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=30,height=5
                            ,stroke_color=YELLOW,stroke_width=20)
        rectangle1.move_to([18,23,0])
        rectangle2=Rectangle(color=BLUE,fill_opacity=0.0,width=30,height=5
                            ,stroke_color=YELLOW,stroke_width=20)
        rectangle2.move_to([10,10,0])
        rectangle3=Rectangle(color=BLUE,fill_opacity=0.0,width=15,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle3.move_to([15,4,0])
        rectangle4=Rectangle(color=BLUE,fill_opacity=0.0,width=20,height=5
                            ,stroke_color=YELLOW,stroke_width=20)
        rectangle4.move_to([11,-3,0])
        rectangle5=Rectangle(color=BLUE,fill_opacity=0.0,width=15,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle5.move_to([12.5,-11,0])
        self.play(Create(rectangle),Create(rectangle1),Create(rectangle2),Create(rectangle3),Create(rectangle4),Create(rectangle5))
        self.wait()